package com.xuecheng.content.controller;

import com.xuecheng.commons.model.dto.TeachplanDto;
import com.xuecheng.commons.model.vo.ResponseResult;
import com.xuecheng.commons.model.vo.TeachplanVo;
import com.xuecheng.commons.utils.BeanHelper;
import com.xuecheng.content.domain.Teachplan;
import org.springframework.web.bind.annotation.*;
import com.xuecheng.content.service.TeachplanService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * <p>
 * 课程计划前端控制器
 * </p>
 *
 * @author HuangYuwu
 */
@Slf4j
@RestController
public class TeachplanController {

    @Autowired
    private TeachplanService  teachplanService;

    /**
     * 查询课程计划列表-树形结构
     * @param courseId
     * @return
     */
    @GetMapping("/teachplan/{courseId}/tree-nodes")
    public ResponseResult treeNodes(@PathVariable("courseId") Long courseId){
        return teachplanService.treeNodes(courseId);
    }

    /**
     * 保存或者更新课程计划
     * @param teachplanDto
     * @return
     */
    @PostMapping("/teachplan")
    public ResponseResult saveOrUpdateTeachplan(@RequestBody TeachplanDto teachplanDto){
        return teachplanService.saveOrUpdateTeachplan(teachplanDto);
    }

    /**
     * 根据id删除课程计划
     * @param id
     * @return
     */
    @DeleteMapping("/teachplan/{id}")
    public ResponseResult deleteTeachplan(@PathVariable("id")Long id){
        return teachplanService.deleteTeachplan(id);
    }

    /**
     * 根据id查询课程计划
     * @param teachplanId
     * @return
     */
    @GetMapping("/teachplan/{teachplanId}")
    public ResponseResult findTeachplanById(@PathVariable("teachplanId")Long teachplanId){
        Teachplan teachplan = teachplanService.getById(teachplanId);
        TeachplanVo teachplanVo = BeanHelper.copyProperties(teachplan, TeachplanVo.class);
        return ResponseResult.okResult(teachplanVo);
    }

}
